﻿using Consul;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Authorization.Common;
using S.Authorization.Common.Dto;
using S.Authorization.Domain.Model.Authority;
using S.Authorization.Domain.Model.Organization;
using S.Authorization.Infrastructure;
using S.Authorization.Read.API.Application.Command.OrganizationCommand;
using S.Authorization.Read.API.Application.Command.SheepFarmsCommand;
using S.Authorization.Read.API.Dto;
using S.Common.Enums.Organization;
using S.Common.Enums.TransFer;
using static S.Authorization.Read.API.Application.Command.MenuCommand.MenuReadAllCommand;

namespace S.Authorization.Read.API.Controllers.Organization
{
    /// <summary>
    /// 栋舍/羊场/栏位
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class ColumnManagementController : BaseController
    {
        public ColumnManagementController(IMediator mediator) : base(mediator)
        {
        }

        /// <summary>
        /// 栋舍分页显示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        //[Authorize(Policy = "AdminOnly")]
        [HttpGet("ColumnList")]
        public async Task<IActionResult> ColumnList(int pageIndex, int PageSize,int? BuildingTypes,string? BuildingName,string? ResponsiblePerson)
        {
            
            return Ok(await mediator.Send(new ColumnManagementListCommand() { PageIndex = (int)pageIndex, PageSize = (int)PageSize,BuildingTypes=BuildingTypes,BuildingName=BuildingName,ResponsiblePerson=ResponsiblePerson }));

        }
        /// <summary>
        /// 栋舍下拉框显示
        /// </summary>
        /// <returns></returns>
        //[Authorize(Policy = "EmployeeOnly")]
        [HttpGet("GetColumnList")]
        public async Task<IActionResult> GetColumnList()
        {

            return Ok(await mediator.Send(new ColumnManagementShowCommand() { }));
        }
        /// <summary>
        /// 栋舍返填
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetColumnById")]
        public async Task<IActionResult> GetColumnById(int id)
        {

            return Ok(await mediator.Send(new ColumnManagementById() { BuildingManagementId=id}));
        }
        /// <summary>
        /// 栏位返填
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetFielById")]
        public async Task<IActionResult> GetFielById(int id,int PageIndex,int PageSize)
        {
            return Ok(await mediator.Send(new FielModelByIdCommand() { BuildingManagementId = id,PageIndex=PageIndex,PageSize=PageSize }));
        }
        /// <summary>
        /// 栏位下拉框显示
        /// </summary>
        /// <returns></returns>
       // [Authorize(Policy = "CustomPolicy")]
        [HttpGet("GetFieldMode")]
        public async Task<IActionResult> GetFieldMode()
        {

            return Ok(await mediator.Send(new FieldModeCommand() { }));
        }
        /// <summary>
        /// 根据栋舍主键显示栏位（二级联动
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetHouseField")]
        public async Task<IActionResult> GetHouseField(int id)
        {

            return Ok(await mediator.Send(new HouseFieldCommand() {id=id }));
        }
        /// <summary>
        /// 根据羊场主键显示栋舍（二级联动)
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSheepFarmHouse")]
        public async Task<IActionResult> GetSheepFarmHouse(int id=0)
        {

            return Ok(await mediator.Send(new SheepFarmHouseCommand() { id = id }));
        }
        /// <summary>
        /// 栋舍状态枚举
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetOrderStates")]
        public List<object> GetOrderStates()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<BuildingEnum>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item,
                });
            }
            return list;
        }
        /// <summary>
        /// 转舍类型枚举
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetTransFerEnum")]
        public List<object> GetTransFerEnum()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<TransFerEnum>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item,
                });
            }
            return list;
        }
        /// <summary>
        /// 羊场规模
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSheepFarmSize")]
        public List<object> GetSheepFarmSize()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<SheepFarmSize>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item,
                });
            }
            return list;
        }
        /// <summary>
        /// 显示羊场
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSheepFarms")]
        public async Task<Pager<SheepFarmsModel>> GetSheepFarms(int pageIndex, int pageSize,string? SheepFarmsFullName,string? Responsible)
        {
            return await mediator.Send(new SheepFarmsGetAllCommand()
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                SheepFarmsFullName = SheepFarmsFullName,
                Responsible = Responsible
            });
        }
        /// <summary>
        /// 显示羊场下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSheepSelectFarms")]
        public async Task<List<SelectDto>> GetSheepSelectFarms()
        {
            return await mediator.Send(new SheepFarmsSelectCommand() { });
        }
        /// <summary>
        /// 羊场返填
        /// </summary>
        /// <param name="SheepFarmsId"></param>
        /// <returns></returns>
        [HttpGet("GetSheepFarmById")]
        public async Task<List<SheepFarmsModel>> GetSheepFarmById(int SheepFarmsId)
        {
            return await mediator.Send(new SheepFarmsByIdCommand() { SheepFarmsId = SheepFarmsId });
        }
        /// <summary>
        /// 单位返填
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        [HttpGet("GetBusinessModelById")]
        public async Task<BusinessModel> GetBusinessModelById()
        {
            return await mediator.Send(new BussinessGetByIdCommand() { UserId = UserStrategyDto.UserId });
        }
    }
}
